﻿Imports System.Data.OleDb
Public Class addChildren
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        If IsPostBack = False Then
            If Request.Params("workerNRC") = "" Then Response.Redirect("acclist.aspx")
            Dim oleDbConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("ClaimsConnectionString").ConnectionString)
            Dim SqlString As String = "Select * From Children Where workerNRC = @f1"
            Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
            cmd.CommandType = CommandType.Text
            cmd.Parameters.AddWithValue("@f1", Request.Params("workerNRC"))
            oleDbConn.Open()
            Dim dataReader = cmd.ExecuteReader
            GridView1.DataSource = dataReader
            GridView1.DataBind()
        End If
    End Sub

    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim oleDbConn As New OleDbConnection(ConfigurationManager.ConnectionStrings("ClaimsConnectionString").ConnectionString)
        Dim SqlString As String = "Insert Into Children (workerNRC, childName, childDob, transactionDate) Values (@f1,@f2, @f3, @f4)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", Request.Params("workerNRC"))
        cmd.Parameters.AddWithValue("@f2", tb_childName.Text)
        cmd.Parameters.AddWithValue("@f3", tb_childDob.Text)
        cmd.Parameters.AddWithValue("@f4", DateTime.Now)
        oleDbConn.Open()
        cmd.ExecuteNonQuery()
        'Response.Redirect("workerConfirmation.aspx")
        'Response.Redirect("addChild.aspx?workerNRC=" & tb_workerNRC.Text)
        'Fill Gridview1 dynamically
        Dim SqlString2 As String = "Select * From Children Where workerNRC = @f5"
        Dim cmd2 As OleDbCommand = New OleDbCommand(SqlString2, oleDbConn)
        cmd2.CommandType = CommandType.Text
        cmd2.Parameters.AddWithValue("@f5", Request.Params("workerNRC"))
        Dim dataReader = cmd2.ExecuteReader
        GridView1.DataSource = dataReader
        GridView1.DataBind()
        tb_childName.Text = ""
        tb_childDob.Text = ""
    End Sub
End Class